﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command;
using B.S.DataBase.MyRead.API.Appicant.Command.Menus;
using MediatR;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler
{
    public class FanTianUpDataMenuCommendHandlers : IRequestHandler<FanTianUpDataMenuCommends, APIResult<List<Menu>>>
    {
        private readonly IBaseRepository<Menu> menuRepository;
        private readonly IMapper mapper;

        public FanTianUpDataMenuCommendHandlers(IBaseRepository<Menu> menuRepository, IMapper mapper)
        {
            this.menuRepository = menuRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 根据菜单ID查询菜单信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIResult<List<Menu>>> Handle(FanTianUpDataMenuCommends request, CancellationToken cancellationToken)
        {
            APIResult<List<Menu>> result = new APIResult<List<Menu>>();
            result.Code =APIEnum.查询成功;
            result.Msg=APIEnum.查询成功.ToString();

            var menus=menuRepository.GetAllAsync().Result;
            result.data = menus.ToList();
            return await Task.FromResult(result);
        }
    }
}
